package com.lx.chong.config;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.stereotype.Component;

/**
 * 自定义生成表名规则，注：若不加此类，linux系统创建表时表名会出现大写。windows不影响
 */
@Component
public class MySQLUpperCaseStrategy extends PhysicalNamingStrategyStandardImpl {

    private static final long serialVersionUID = 1383021413247872469L;


    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
        // 将表名全部转换成小写，为解决windows与linux系统创建表时统一。
        String tableName = name.getText().toLowerCase();
        // 返回转换之后的表名
        return Identifier.toIdentifier(tableName);
    }

}